package com.dingwei.lesyndrome.ui.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.allen.library.SuperButton;
import com.dingwei.lesyndrome.R;
import com.dingwei.lesyndrome.bean.IdCodeBean;
import com.dingwei.lesyndrome.mvp.presenter.ForgetPasswordPresenter;
import com.dingwei.lesyndrome.mvp.view.Contract;
import com.lihao.baselibrary.base.BaseActivity;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created time 2018/2/26.
 * Creator 南柯一梦丶 on
 * Personal signature 余生还长 何必慌张
 * Page description : 找回密码
 */

public class ForgetPasswordActivity extends BaseActivity implements Contract.ForgetPasswordView {
    ForgetPasswordPresenter forgetPasswordPresenter = new ForgetPasswordPresenter(this);
    @Bind(R.id.et_phone)
    EditText etPhone;
    @Bind(R.id.et_code)
    EditText etCode;
    @Bind(R.id.tv_get_code)
    TextView tvGetCode;
    @Bind(R.id.et_new_password)
    EditText etNewPassword;
    @Bind(R.id.et_confirm_new_password)
    EditText etConfirmNewPassword;
    @Bind(R.id.btn_submit)
    SuperButton btnSubmit;

    @Override
    protected int getContentViewId() {
        return R.layout.activity_forget_password;
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initView() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.tv_get_code, R.id.btn_submit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_get_code:
                forgetPasswordPresenter.getImgCode(etPhone.getText().toString());
                break;
            case R.id.btn_submit:
                forgetPasswordPresenter.forgetPassword(etPhone.getText().toString(),etCode.getText().toString(),etNewPassword.getText().toString(),etConfirmNewPassword.getText().toString());
                break;
        }
    }

    @Override
    public void CountDownTimerFinish() {
        tvGetCode.setTextColor(getResources().getColor(R.color.blue));
        tvGetCode.setText("获取验证码");
        tvGetCode.setEnabled(true);
    }

    @Override
    public void CountDownTimerOnTick(long millisUntilFinished) {
        tvGetCode.setTextColor(getResources().getColor(R.color.text_color_gray));
        tvGetCode.setText("请等待" + millisUntilFinished / 1000 + "秒");
        tvGetCode.setEnabled(false);
    }

    @Override
    public void getCodeSuccess(IdCodeBean bean) {
        etCode.setText(bean.data);
    }

    @Override
    public void forgetPasswordSuccess() {
        showToast("找回密码成功,请登录");
        finish();
    }
}
